/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package motiveai.tests;

import com.jme3.light.AmbientLight;
import com.jme3.math.ColorRGBA;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.AbstractControl;
import com.jme3.scene.control.Control;

/**
 *
 * @author oxplay
 */
public class HighLightControl extends AbstractControl {

    private boolean highlighted = false;
    private AmbientLight al = new AmbientLight();
    private float highLightTimeout = 0f;

    public void highlight(float time, ColorRGBA color) {
        al.setColor(color);
        if (!highlighted) {
            spatial.addLight(al);
            highlighted = true;
        }
        highLightTimeout = time;
    }

    @Override
    public void setSpatial(Spatial spatial) {
        super.setSpatial(spatial);
    }

    @Override
    protected void controlUpdate(float tpf) {
        if (highlighted && highLightTimeout < 0) {
            highLightTimeout -= tpf;
            spatial.removeLight(al);
            highlighted = false;
        } else {
            highLightTimeout -= tpf;
        }
    }

    @Override
    protected void controlRender(RenderManager rm, ViewPort vp) {
    }

    public Control cloneForSpatial(Spatial spatial) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
